package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.UpdateWxHeadImgBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.UpdateWxHeadImgCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.ThirdpartyUserbindHistory;
import com.ymttest.database.sqlwapper.JUserWapper;
/**
*更新微信头像
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateWxHeadImg{
	private static UpdateWxHeadImgBean updatewxheadimgBean;
	private static UpdateWxHeadImgCall updatewxheadimgCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新微信头像");
	}

	@Before
	public void caseUp() {
		updatewxheadimgBean=new UpdateWxHeadImgBean();
		updatewxheadimgCall=new UpdateWxHeadImgCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatewxheadimgCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateWxHeadImg_001() {
		Logger.start(true,"更新微信头像成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			updatewxheadimgBean.setUserId(uid);
			updatewxheadimgBean.setHeadImg("headimg2");
			updatewxheadimgCall.setData(updatewxheadimgBean);
			updatewxheadimgCall.callService();	
			Logger.verifyEquals("true", updatewxheadimgCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", updatewxheadimgCall.getString("ResponseCode"), "验证ResponseCode");
			
			Logger.comment("验证thirdparty_userbind_history");
			JUserWapper ju=new JUserWapper();
			ThirdpartyUserbindHistory thirdinfohist = ju.selectthirdpartyuserbindhistory(uid).get(0);
			Logger.verifyEquals(updatewxheadimgBean.getHeadImg(), thirdinfohist.getHeadimgurl(), "验证Headimgurl");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateWxHeadImg_002() {
		Logger.start(true,"多渠道更新微信头像成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
//			Thread.sleep(1000);
			bd.setAppSource(AppSourceEnum.Wap);
			bd.setHeadimgurl("headimg1");
			JUserCallService.bindThirdPartyUserCall(bd);
			updatewxheadimgBean.setUserId(uid);
			updatewxheadimgBean.setHeadImg("headimg2");
			updatewxheadimgCall.setData(updatewxheadimgBean);
			updatewxheadimgCall.callService();	
			Logger.verifyEquals("true", updatewxheadimgCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", updatewxheadimgCall.getString("ResponseCode"), "验证ResponseCode");
			
			Logger.comment("验证thirdparty_userbind_history");
			JUserWapper ju=new JUserWapper();
			ThirdpartyUserbindHistory thirdinfohist = ju.selectthirdpartyuserbindhistory(uid).get(0);
			Logger.verifyEquals(updatewxheadimgBean.getHeadImg(), thirdinfohist.getHeadimgurl(), "验证Headimgurl");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateWxHeadImg_003(){
		Logger.start(true,"不输入url不更新微信头像");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			updatewxheadimgBean.setUserId(uid);
//			updatewxheadimgBean.setHeadImg("headimg2");
			updatewxheadimgCall.setData(updatewxheadimgBean);
			updatewxheadimgCall.callService();	
			Logger.verifyEquals("false", updatewxheadimgCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", updatewxheadimgCall.getString("ResponseCode"), "验证ResponseCode");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateWxHeadImg_004(){
		Logger.start(true,"输入url为空不更新微信头像");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			BindThirdPartyUserReq bd = JUserCallService.initBindThirdUserReq(uid);
			bd.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
			JUserCallService.bindThirdPartyUserCall(bd);
			updatewxheadimgBean.setUserId(uid);
			updatewxheadimgBean.setHeadImg("");
			updatewxheadimgCall.setData(updatewxheadimgBean);
			updatewxheadimgCall.callService();	
			Logger.verifyEquals("false", updatewxheadimgCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", updatewxheadimgCall.getString("ResponseCode"), "验证ResponseCode");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}